package com.situ.day9;

import org.junit.Test;

public class HomeWork {

    @Test
    public void test1() {
        //String str = "---java Android---";
        //String str = "------";
        //String str = "";
        //String str = "---java Android";
        //String str = "java Android---";
        String str = null;
        String newStr = trim(str);
        System.out.println(newStr);
    }

    private String trim(String str) {
        //"" null 卫操作
        if (str == null || str.equals("")) {
            return "";
        }

        int startIndex = 0;
        int endIndex = str.length() - 1;

        while ((startIndex <= endIndex) && (str.charAt(startIndex) == '-')) {
            startIndex++;
        }
        while ((startIndex <= endIndex) && (str.charAt(endIndex) == '-')) {
            endIndex--;
        }

        return str.substring(startIndex, endIndex + 1);
    }


    public static void main(String[] args) {
        String str = "hello";
        char ch = str.charAt(5);
        System.out.println(ch);
    }

    @Test
    public void test45() {
        String str = "Hello Java";
        System.out.println(str.toLowerCase());
        System.out.println(str.toUpperCase());
        String newStr = toLowerCase(str);
        System.out.println(newStr);
    }

    private String toLowerCase(String str) {
        char[] array = str.toCharArray();
        for (int i = 0; i < array.length; i++) {
            if (array[i] >= 'A' && array[i] <= 'Z') {
                array[i] = (char)(array[i] + 32);
            }
        }
        return new String(array);
    }


}
